package sjsu.cmpe272;
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.*;

import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;




@SuppressWarnings("serial")
public class FoodtruckServlet extends HttpServlet 
{
	public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException 
	{
		resp.setContentType("text/plain");
		resp.getWriter().println("Hello, world");
		
		PrintWriter out = resp.getWriter();
		
		UserService userService = UserServiceFactory.getUserService();
	    User user = userService.getCurrentUser();
	    if (user != null)
	    {
            resp.setContentType("text/html");
            resp.getWriter().println("Hello, " + user.getNickname());
        } 
	    else 
        {
            resp.sendRedirect(userService.createLoginURL(req.getRequestURI()));
        }
	   // userService.createLogoutURL(req.getRequestURI());
	    String title = "logout out";
	    out.println(
	                "<HTML><BODY BGCOLOR=\"#FDF5E6\">\n" +
	                "<H1 ALIGN=CENTER>" + title + "</H1>\n" );
	    
	    			out.println("</BODY></HTML>");
	    			
	    			
	    			
	}
}
